//
//  MineViewController.m
//  WangYiNews
//
//  Created by lanou3g on 15/10/10.
//  Copyright (c) 2015年 zhengming. All rights reserved.
//

#import "MineViewController.h"

enum Section {
    sectionOne,
    sectionTwo,
    sectionThree
};

@interface MineViewController ()<UITableViewDataSource, UITableViewDelegate>

@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self subView];
}

#pragma mark -视图布局
- (void)subView
{
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
    imageView.backgroundColor = [UIColor yellowColor];
    imageView.layer.cornerRadius = imageView.frame.size.width / 2;
    imageView.layer.masksToBounds = YES;
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 85, 80, 20)];
    label.text = @"立即登录";
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    
    
    [self.headImageBtn addSubview:imageView];
    [self.headImageBtn addSubview:label];
    [self.headImageBtn addTarget:self action:@selector(headImageBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self customButton:self.readBtn image:nil imageFrame:CGRectMake(self.readBtn.frame.size.width / 3 - 10, 5, 20, 20) labelFrame:CGRectMake(self.readBtn.frame.size.width / 3 - 10, 25, 20, 20) labelText:@"阅读" textColor:[UIColor grayColor] textFont:[UIFont systemFontOfSize:10]];
    [self customButton:self.collectionBtn image:nil imageFrame:CGRectMake(self.readBtn.frame.size.width / 3 - 10, 5, 20, 20) labelFrame:CGRectMake(self.readBtn.frame.size.width / 3 - 10, 25, 20, 20) labelText:@"收藏" textColor:[UIColor grayColor] textFont:[UIFont systemFontOfSize:10]];
    [self customButton:self.commentBtn image:nil imageFrame:CGRectMake(self.readBtn.frame.size.width / 3 - 10, 5, 20, 20) labelFrame:CGRectMake(self.readBtn.frame.size.width / 3 - 10, 25, 20, 20) labelText:@"跟帖" textColor:[UIColor grayColor] textFont:[UIFont systemFontOfSize:10]];
    [self customButton:self.moneyBtn image:nil imageFrame:CGRectMake(self.readBtn.frame.size.width / 3 - 10, 5, 20, 20) labelFrame:CGRectMake(self.readBtn.frame.size.width / 3 - 10, 25, 20, 20) labelText:@"金币" textColor:[UIColor grayColor] textFont:[UIFont systemFontOfSize:10]];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
}

#pragma mark -按钮触发方法
// 头像点击事件
- (void)headImageBtnAction:(UIButton *)headImageBtn
{
    NSLog(@"head");
}

#pragma mark -实现UITableViewDataSource, UITableViewDelegate代理协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case sectionOne:
            return 1;
            break;
        case sectionTwo:
            return 3;
            break;
        case sectionThree:
            return 1;
            break;
            
        default:
            return 0;
            break;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] init];
    }
    
    switch (indexPath.section) {
        case sectionOne:
            cell.imageView.backgroundColor = [UIColor blueColor];
            cell.textLabel.text = @"我的消息";
            break;
        case sectionTwo:
            if (indexPath.row == 0) {
                cell.imageView.backgroundColor = [UIColor blueColor];
                cell.textLabel.text = @"金币商城";
            } else if (indexPath.row == 1) {
                cell.imageView.backgroundColor = [UIColor blueColor];
                cell.textLabel.text = @"我的任务";
            } else if (indexPath.row == 2) {
                cell.imageView.backgroundColor = [UIColor blueColor];
                cell.textLabel.text = @"我的钱包";
            }
            break;
        case sectionThree:
            cell.imageView.backgroundColor = [UIColor blueColor];
            cell.textLabel.text = @"我的邮箱";
        default:
            break;
    }
    cell.imageView.image = [UIImage imageNamed:@"account_snslogin_icon_3@2x"];
    cell.textLabel.font = [UIFont systemFontOfSize:12];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 5;
}

#pragma mark -自定义Button
// 该自定义button包含一个image和一个label
- (void)customButton:(UIButton *)button image:(UIImage *)image imageFrame:(CGRect)imageFrame labelFrame:(CGRect)labelFrame labelText:(NSString *)text textColor:(UIColor *)color textFont:(UIFont *)font
{
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageFrame];
    imageView.image = image;
    imageView.backgroundColor = [UIColor yellowColor];
    [button addSubview:imageView];
    UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
    label.text = text;
    label.textColor = color;
    label.textAlignment = NSTextAlignmentCenter;
    label.font = font;
    [button addSubview:label];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
